package com.symone.webcms.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.symone.webcms.config.GlobalConfig;
import com.symone.webcms.mapper.ConfigMapper;
import com.symone.webcms.model.Config;
import com.symone.webcms.service.ConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 *　　
 *   @description : Config 服务实现类
 *   ---------------------------------
 * 	 @author Archer Chu
 *   @since 2019-01-07
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {

    @Override
    public int delete(long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public boolean deleteFlagById(long id) {
        return baseMapper.deleteFlagById(id);
    }

    @Override
    public int clear() {
        return baseMapper.delete(new EntityWrapper<Config>().eq("deleted" ,1));
    }

    @Override
    @Transactional
    public boolean save(Map<String, String> requestMap) {
        for(String code:requestMap.keySet()) {
            if( !baseMapper.updateValue(code,requestMap.get(code))){
                return false;
            }
            GlobalConfig.getInstance().put(code,requestMap.get(code));
        }
        return true;
    }

}
